# -*- coding: utf-8 -*-
# author: sixmillions
# date: 2022/3/16

# 序列-列表
print(type([1, 2, 3]))  # <class 'list'>
print(type([1]))  # <class 'list'>
print(type([]))  # <class 'list'>
# 里面元素的类型可以不同
print([1, 'AAA', False, 6.22, True])  # [1, 'AAA', False, 6.22, True]
# 列表里面还可以嵌套列表
print([[1, 2], [3, 4, [111, 222]], 'ABC'])  # [[1, 2], [3, 4, [111, 222]], 'ABC']

# 列表索引
a = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# 结果是具体类型
print(a[2])  # 2
print(a[-1])  # 9
# 结果是列表
print(a[-1:])  # [9]
# 切片
print(a[2:3])  # [2]
print(a[2:5])  # [2, 3, 4]
print(a[-3:])  # [7, 8, 9]
print(a[-1:])  # [9]
print(a[-3:])  # [7, 8, 9]
print(a[-1::-1])  # [9, 8, 7, 6, 5, 4, 3, 2, 1, 0]

# 修改某个值
a[0] = "A"
print(a)  # ['A', 1, 2, 3, 4, 5, 6, 7, 8, 9]
a[1] = ['B', 'C', 'D']
print(a)  # ['A', ['B', 'C', 'D'], 2, 3, 4, 5, 6, 7, 8, 9]

# 列表相加
print([1, 2, 3] + [4, 5, 6])
# 列表重复
print([1, 2, 3] * 4)

# 判断元素存在
b = [1, 2, 3, 4, 5]
print(2 in b)  # True
print(6 not in b)  # True

# 查看长度
print(len(b))  # 5
# 最大最小素，根据asc码表
print(max(b))  # 5
print(min(b))  # 1

# 查看asc码表对应的值
print(ord("中"))
print(ord("国"))

# 追加元素
c = [1, 2, 3]
c.append(5)  # [1, 2, 3, 5]
print(c)
c.append([6, 7])
print(c)  # [1, 2, 3, 5, [6, 7]]
c.append('e')
print(c)  # [1, 2, 3, 5, [6, 7], 'e']

# pop删除元素
d = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
print("原始list：", d)  # 原始list： [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
# 默认删除列表末尾的数据
d.pop()
print("删除末尾后：", d)  # 删除末尾后： [0, 1, 2, 3, 4, 5, 6, 7, 8]
# 删除制定索引位置
d.pop(2)
print("删除制定索引位置上的数据", d)  # [0, 1, 3, 4, 5, 6, 7, 8]

# remove删除元素
e = ['A', "b", 'c', 'e']
print("原始list：", e)  # 原始list： ['A', 'b', 'c', 'e']
# 删除具体元素
e.remove('A')
print('删除具体元素：', e)  # 删除具体元素： ['b', 'c', 'e']
# 删除不存在元素，会报错
# e.remove('S')
# print("删除不存在元素", e)  # list.remove(x): x not in list

# 翻转字符串
f = [0, 1, 3, 4, 5, 6, 7, 8, 9]
print("原始list：", d)  # 原始list： [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
f.reverse()
print("翻转字符串：", f)
